package cn.itsource.org.controller;

import cn.itsource.basic.domain.AjaxResult;
import cn.itsource.basic.domain.BaseQuery;
import cn.itsource.basic.util.PageList;
import cn.itsource.org.domain.Employee;
import cn.itsource.org.domain.RegisterDto;
import cn.itsource.org.domain.Shop;
import cn.itsource.org.service.EmployeeService;
import cn.itsource.org.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@Controller + @ResponseBody
@RestController
@RequestMapping("shop")
/**
 * @Api 作用在类上 value 里面填写的是当前类的文档描述
 */
@Api(value = "店铺管理的接口文档",description = "店铺管理的接口文档")
public class ShopController {
    @Autowired
    ShopService shopServiceImpl;

    @ApiOperation(value = "查询所有", notes = "查询所有")

    @GetMapping("/findall")
    public List<Shop> findall(){
        return shopServiceImpl.findAll();
    }

    @ApiOperation(value = "单个查询", notes = "单个查询")
    @GetMapping("/findOne/{id}")
    public Shop findOne(@PathVariable Long id){
        Shop one = shopServiceImpl.findOne(id);
        System.out.println(one);
        return one;
    }

    @ApiOperation(value = "高级分页查询", notes = "高级分页查询")
    @PostMapping("/findPage")
    public PageList<Shop> findPage(@RequestBody BaseQuery baseQuery){
        return shopServiceImpl.findPage(baseQuery,"name");
    }

    @ApiOperation(value = "审核驳回", notes = "审核驳回")
    @PostMapping("/back")
    public void back(@RequestBody Shop shop){
        System.out.println(shop.getState());
        shopServiceImpl.back(shop);
    }

    @ApiOperation(value = "审核通过", notes = "审核通过")
    @PostMapping("/upstate")
    public void upstate(@RequestBody Shop shop){
        System.out.println(shop.getState());
        shopServiceImpl.upstate(shop);
    }

    @ApiOperation(value = "批量删除", notes = "批量删除")
    @PostMapping("/deleteBatch")
    public void deleteBatch(@RequestBody List<Long> ids){
        shopServiceImpl.deleteBatch(ids);
    }

    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/add")
    public void insert(@RequestBody Shop shop){
        shopServiceImpl.insert(shop);
    }

    @ApiOperation(value = "修改", notes = "修改")
    @PostMapping("/update")
    public void update(@RequestBody Shop shop){
        shopServiceImpl.update(shop);
    }

    //注册
    /*
    * @Validated:需要判断字段的条件
    * */
    @PostMapping("/register")
    public AjaxResult register(@RequestBody @Validated RegisterDto dto){
        return shopServiceImpl.register(dto);
    }

    @GetMapping("/state/{uuid}")
    public AjaxResult state(@PathVariable String uuid){
        AjaxResult result = shopServiceImpl.state(uuid);
        return result;
    }

    @GetMapping("findByshopId")
    public Shop findByshopId(){
        return shopServiceImpl.findByshopId();
    }
}
